postgresql发送异步非阻塞 协程命令
function Coroutine\PostgreSQL->query(resource $connection);
example:
go(function () {
$pg = new Swoole\Coroutine\PostgreSQL();
$conn = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=root password=");
$result = $pg -> query('SELECT * FROM test;');
$arr = $pg -> fetchAll($result);
var_dump($arr);
});
返回insert id:
go(function () {
$pg = new Swoole\Coroutine\PostgreSQL();
$conn = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=wuzhenyu password=");
$result = $pg -> query("insert into test (id,text) VALUES (24,'text') RETURNING id ;");
$arr = $pg -> fetchRow($result);
var_dump($arr);
});
?>
也可以多次提交query 命令 ,如begin commit
go(function () {
$pg = new Swoole\Coroutine\PostgreSQL();
$conn = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=root password=");
$pg -> query('BEGIN;');
$result = $pg -> query('SELECT * FROM test;');
$arr = $pg -> fetchAll($result);
$pg -> query('COMMIT;');
var_dump($arr);
});